<template>
    <a-form ref="formRef" :model="formData">
        <a-form-item field="name" label="众筹名" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.name" placeholder="请输入众筹名"></a-input>
        </a-form-item>
        <a-form-item field="img" label="封面图" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <ma-upload v-model="formData.cover" title="封面图" type="image"></ma-upload>
        </a-form-item>
        <a-form-item field="price" label="每份金额" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.price" placeholder="请输入每份金额"></a-input>
        </a-form-item>
        <a-form-item field="interest" label="每日利息" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.interest" placeholder="请输入每日利息"></a-input>
        </a-form-item>
        <a-form-item field="copies_all" label="总份数" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input-number v-model="formData.copies_all" placeholder="请输入总份数" />
        </a-form-item>
        <a-form-item field="copies_all" label="众筹天数" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input-number v-model="formData.days" placeholder="请输入众筹天数" />
        </a-form-item>
        <a-form-item field="stock" label="日期" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-range-picker showTime v-model="default_value" @change="change" />
        </a-form-item>
        <a-form-item field="content" label="详情" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <MaEditor v-model="formData.content"></MaEditor>
        </a-form-item>
    </a-form>
</template>
<script  setup>
import { ref } from "vue";
import crowdfunding from '@/api/crowdfunding'
import { Message } from "@arco-design/web-vue";
const emit = defineEmits(["refreshList"]);

const props = defineProps({
    id: [String, Number]
});

const formData = ref({});

let default_value = ref([]);
const getDeta = async () => {
    let { data: { data } } = await crowdfunding.get_deta(props.id);
    let date = [data.start_date, data.end_date];
    default_value.value = date;

    data.start = data.start_date;
    data.end = data.end_date;
    formData.value = data;
};
props.id ? getDeta() : "";

const change = (time) => {
    formData.value.start = time[0];
    formData.value.end = time[1];
};
const submit = async () => {
    await crowdfunding.save(formData.value);
    Message.success("保存成功");
    setTimeout(() => emit("refreshList"), 500);
};
defineExpose({ submit });
</script>